package com.ln.asset.core.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ln.asset.core.config.LendNoUtils;
import com.ln.asset.core.mapper.AssetInfoMapper;
import com.ln.asset.core.pojo.AssetInfo;
import com.ln.asset.core.pojo.RecRecipients;
import com.ln.asset.core.mapper.RecRecipientsMapper;
import com.ln.asset.core.service.RecRecipientsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 资产领用记录表 服务实现类
 * </p>
 *
 * @author cuixiaoxin
 * @since 2022-04-28
 */
@Service
public class RecRecipientsServiceImpl extends ServiceImpl<RecRecipientsMapper, RecRecipients> implements RecRecipientsService {

    @Resource
    private AssetInfoMapper assetInfoMapper;
    @Resource
    private RecRecipientsMapper recRecipientsMapper;

    @Override
    public IPage<RecRecipients> getRecListPage(Page<RecRecipients> page) {
        Page<RecRecipients> pages = baseMapper.selectPage(page, null);
        return pages;
    }

    @Override
    public void insertRec(RecRecipients rec) {
        rec.setRStatus(0);
        rec.setIsDeleted(0);
        rec.setRNo(LendNoUtils.getRec());
        baseMapper.insert(rec);
    }

    @Override
    public RecRecipients getRecById(Integer rId) {
        return baseMapper.selectById(rId);
    }

    @Override
    public void updateRecStatus(Integer status, RecRecipients recRecipients) {
        System.out.println(recRecipients);
        if(status==1){
            recRecipients.setRStatus(1);
            baseMapper.updateById(recRecipients);
        }else if(status==0){
            recRecipients.setRStatus(2);
            baseMapper.updateById(recRecipients);
        }else if(status==3){
            recRecipients.setRStatus(3);
            baseMapper.updateById(recRecipients);
        }
    }

    @Override
    public void deleteById(Integer rId) {
        baseMapper.deleteById(rId);
    }

    @Override
    public List<AssetInfo> selectAllAsset() {
        return assetInfoMapper.selectList(null);
    }

    @Override
    public void saveRec(RecRecipients recRecipients) {
        recRecipients.setRStatus(4);
        baseMapper.updateById(recRecipients);
    }

    @Override
    public void saveRecZhong(Integer rId, ArrayList<Integer> objects) {
        recRecipientsMapper.saveRecZhong(rId,objects);
    }

    @Override
    public List<AssetInfo> selectRecAndAsset(Integer rid) {
        return recRecipientsMapper.selectRecAndAsset(rid);
    }
}
